using Game;
using UnityEngine;
using Voxels;

public class TestDestroyVoxels : MonoBehaviour {
	public LayerMask CastMask;

	private void Update() {
		/*if ( Physics.Raycast(transform.position, -Vector3.up, out var hit, 1f, CastMask, QueryTriggerInteraction.Ignore) ) {
			ProcessHit(hit);
		}
		*/
	}
	/*
	void ProcessHit(RaycastHit hit) {
		var chunkR = hit.collider.GetComponent<ChunkRenderer>();
		if ( !chunkR ) {
			return;
		}
		var point = hit.point - hit.normal * 0.03f;
		var chunk = chunkR.Chunk;
		if ( chunk == null ) {
			return;
		}
		var pos = chunk.GetBlockPosFromWorldPos(point);
		Debug.Log(pos);
		chunk.RemoveBlock(pos.x, pos.y, pos.z);
	}
	*/
	private void OnCollisionEnter(Collision collision) {
		var chunkR = collision.collider.GetComponent<SingleChunkProcessor>();
		if ( !chunkR ) {
			return;
		}

		foreach ( var contact in collision.contacts ) {
			var point = contact.point - contact.normal * 0.03f;

			var pos = chunkR.GetBlockPosFromWorldPos(point);
			Debug.Log(pos);
			chunkR.RemoveBlock(pos);
		}
	}
}
